﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using LPV_POS.Module;


    class Mod_tonkhothientai
    {
       // Mod_baocao baocao;
        public void rpt_baocaotonkhohientai(DataSet dset, ReportDocument rpt, string khohang)
        {

            try
            {
                Mod_header_report header_report = new Mod_header_report();
                header_report.f_header_report(rpt);

                CrystalDecisions.CrystalReports.Engine.TextObject str_khohang;
                str_khohang = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_khohang"];
                str_khohang.Text = khohang;

                rpt.SetDataSource(dset.Tables[0]);
                rpt.DataDefinition.FormulaFields["MA"].Text = "{dt_report.OBJID}" + "";
                rpt.DataDefinition.FormulaFields["HANGHOA"].Text = "{dt_report.OBJNAME}" + "";
                rpt.DataDefinition.FormulaFields["TONKHO"].Text = "{dt_report.SOLUONGTON}" + "";

                mh_save frm_save = new mh_save();
                frm_save.ShowDialog();
                if (frm_save.path_excel == "")
                    return;

                //   xuat file excel
                ExportOptions CrExportOptions;

                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                ExcelFormatOptions CrFormatTypeOptions = new ExcelFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = frm_save.path_excel;
                CrExportOptions = rpt.ExportOptions;
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType = ExportFormatType.Excel;
                CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions = CrFormatTypeOptions;
                rpt.Export();

            }
            catch (Exception ex)
            {

                rpt.Dispose();
                Mod_messagebox mess = new Mod_messagebox();
                mess.messagebox_pos("Thông báo", "Xuất báo cáo thành file pdf không thành công", loaithongbao.canhbao.GetHashCode());
                //throw;
            }
            rpt.Dispose();
            Variable.str_path = "";
        }

    }

